#
# pH+
#

module Ph

	class Resource

		STATIC = 0
		DYNAMIC= 1
	  DATA   = 2
		
		attr_reader :file, :name, :classname, :type
		attr_accessor :cache

		def initialize(file)
			@cache = false
			@file  = file
			# TODO Customize This for Other resources
			@type  = File.extname(@file)
			# TODO This is a hack should be removed.
			@file  = file + '.rb' if @type == ''
			@name  = File.basename(@file, @type)
		end

		def post
		end

		def put
		end

		def delete
		end

		def get(session)
			
			return @cache if @cache
			
			case @type
			when ".rb"
				$".delete @file
				require @file
				classname = session.application.prefix + @name.capitalize + 'Page'
				
				cache = eval("#{classname}.new(session, self).get")
				@cache = cache if session.application.cache 
			when '.css', '.jpeg', '.gif', '.jpg', '.png'
				cache = File.new(@file, 'rb').read if File.exists?(@file)
				@cache = cache if session.application.cache
			else
				raise RuntimeError, "Resource not implemented."
			end

			return cache
			
		end

	end

end
